package service;

import dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.User;

/**
 * @ Author     ：LILA3
 * @ Date       ：Created in 4:35 PM 7/24/2018
 */
@Service
public class LoginService {
    @Autowired
    UserDao userDao;

    public LoginService() {
        System.out.println(LoginService.class.getName());
    }

    public String login(User user) {
        try {
            if (userDao.findByName(user.getName()) == null) {
                return "none user";
            } else {
                if (user.getPassword().equals(user.getPassword())) {
                    return user.getName();
                } else {
                    return "pw fail";
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "未知错误";
        }
    }

    public String register(User user) {
        try {
            if (userDao.findByName(user.getName()) != null) {
                return "user is used";
            }
            userDao.insert(user);
        } catch (Exception e) {
            e.printStackTrace();
            ;
            return "";
        }
        return "register success";
    }
}
